package application

import (
	"gitee.com/alex_li/rodinbell/etc"
	cache "github.com/UncleBig/goCache"
	"time"
)

var c *cache.Cache

func InitCache(expir time.Duration, cleanup time.Duration) {
	c = cache.New(expir, cleanup)
}

func RefreshCache(data string) (refreshed bool) {
	if val, found := c.Get(data); found {
		value := val.(int)
		value = value % 10000
		_ = c.Replace(data, value + 1, time.Duration(etc.Config.Cache.Expir) * time.Second)
		return true
	} else {
		c.Set(data, 1, time.Duration(etc.Config.Cache.Expir) * time.Second)
		return false
	}
}